/**
 * Created with WebStorm.
 * @Author: panda
 * @Date: 2022-05-18 09:25
 * @Description: 评论接口
 */
import {createRequestClient} from './axios/request';
import {APISchema} from "@/api/axios/type";
import localCache from "@/utils/localCache";

interface CommentSchema extends APISchema {
  sendArticleComment: {
    request: {
      id: number, rootId: number, toCommentId: number, toCommentUserId: number, content: string
    };
    response: {
      code: number,
      msg: string
    };
  };
  getArticleComment: {
    request: {
      id: number,
      pageNum: number,
      pageSize: number
    };
    response: {
      code: number,
      msg: string
      data: {
        rows: [
          {
            children: [
              {
                content: string,
                createBy: string,
                createTime: string,
                id: string,
                rootId: string,
                toCommentId: string,
                toCommentUserId: string,
                toCommentUsername: string,
                type: string,
                username: string
              }
            ],
            content: string,
            createBy: string,
            createTime: string,
            id: string,
            rootId: string,
            toCommentId: string,
            toCommentUserId: string,
            toCommentUsername: string,
            type: string,
            username: string
          }
        ],
        total: string
      }
    };
  };
  getVideoComment: {
    request: {
      id: number,
      pageNum: number,
      pageSize: number
    };
    response: {
      code: number,
      msg: string,
      data: {
        rows: [
          {
            children: [
              {
                content: string,
                createBy: string,
                createTime: string,
                id: string,
                rootId: string,
                toCommentId: string,
                toCommentUserId: string,
                toCommentUsername: string,
                type: string,
                username: string
              }
            ],
            content: string,
            createBy: string,
            createTime: string,
            id: string,
            rootId: string,
            toCommentId: string,
            toCommentUserId: string,
            toCommentUsername: string,
            type: string,
            username: string
          }
        ],
        total: string
      }

    };
  };
  sendVideoComment: {
    request: { id: number, rootId: number, toCommentId: number, toCommentUserId: number, content: string };
    response: {
      code: number,
      msg: string
      data: {
        rows: [
          {
            children: [
              {
                content: string,
                createBy: string,
                createTime: string,
                id: string,
                rootId: string,
                toCommentId: string,
                toCommentUserId: string,
                toCommentUsername: string,
                type: string,
                username: string,
                avatar:string
              }
            ],
            content: string,
            createBy: string,
            createTime: string,
            id: string,
            rootId: string,
            toCommentId: string,
            toCommentUserId: string,
            toCommentUsername: string,
            type: string,
            username: string,
            avatar:string
          }
        ],
        total: string
      }
    }
  }

}

export const commentApi = createRequestClient<CommentSchema>({
  baseURL: process.env.NODE_ENV === 'development'
    ? process.env.VUE_APP_API_HOST + ''
    : '',
  apis: {

    sendArticleComment: {
      method: 'POST',
      path: 'POST /articles/:id/comments',
      headers: {'token': localCache.getCache('token')}
    },
    sendVideoComment: {
      method: 'POST',
      path: 'POST /videos/:id/comments',
      headers: {'token': localCache.getCache('token')}
    },
    getArticleComment: 'GET /articles/:id/comments',
    getVideoComment: 'GET /videos/:id/comments'
  }
});
